<template><!--团队排行-->
	<div id="test">
    <!--<title-top :fnlist="initObj.Fnlist"></title-top>-->
    <table-body :options="initObj"></table-body>
    <Modal v-model="pdfModal"
      	title="pdf预览"
      	width="60"
      	:mask-closable = "false"
      	footer-hide
      	>
      	<!--<iframe src="http://172.18.100.4:18769/ftp/edu-ftp/viewOnline/pdf/F102b386-f32c-4868-902f-00bc1886145b" width="100%" height="600px" ></iframe>-->
        <iframe :src="pdfUrl" width="100%" height="600px" scrolling="none" frameborder="0"></iframe>
	</Modal>
	<Modal v-model="submitRecordModal"
      	:title="`${(currentTeam || {}).teamName}_解决题目详情`"
      	width="60"
      	:mask-closable = "false"
      	footer-hide
      	>
      	<!-- <TableList 
			:columns="listCol" 
			:data="rightSubmitList" 
			:total="rightSubmitTotal" 
			:page.sync="pageNow"
			:size.sync="pageSize"
			:max-height="600"
			@queryFun="getAttackSuccess"
		>
		</TableList> -->
		<Table :columns="listCol" :data="rightSubmitList"></Table>
		<Page 
			style="padding: 15px; text-align: center;"
			:total="rightSubmitTotal" 
			:current="pageNow" 
			:page-size="10" 
			show-total 
			show-elevator 
			@on-change="pageChange"/>
	</Modal>
	<Modal v-model="penalizedModal"
      	:title="penalizedTitle"
      	width="60"
      	:mask-closable = "false"
      	footer-hide
      	>
      	<Table :columns="columns" :data="penalizedTeamList" :loading="tableLoading" :max-height="300"></Table>
	</Modal>
	<package-progress
			:show="showProgress"
			:progress="progress"
			:status="progressStatus"
			@change="change"
			title="打包进度"
	></package-progress>
    <Modal
            v-model="showModal"
            width="800"
            :title="title"
            footer-hide>
        <Table
                border
                :columns="staticColumns"
                :data="staticList"></Table>
        <Page
                style="padding: 15px; text-align: center;"
                :total="staticTotal"
                :current="staticCurrentPage"
                :page-size="staticPageSize"
                show-total
                show-elevator
                @on-change="staticChangePage"
                @on-page-size-change="staticChangePageSize"></Page>
    </Modal>
	<Modal
		v-model="questionModal.show"
		width="400"
		title="按照题目下载报告"
		footer-hide>
		<div class="flex">
			<Select filterable
				v-model="questionModal.question"
				placeholder="请选择题目"
				label-in-value
				filterable
				>
				<Option
					v-for="target in targetList"
					:title="target.name"
					:value="target.questionId"
					:key="target.questionId"
					:label="target.name"
					>{{ target.name }}</Option
				>
			</Select>
			<Button type="primary" :disabled="!questionModal.question" @click="downloadQuestionAllReport" class="ml10">打包下载</Button>
		</div>
	</Modal>
  </div>
</template>
<script>
//	import Cookies from 'js-cookie'
  import {ctfTeamRankStatis,ctfExportRank,downloadSceneAllReport,downloadSubmitAllReport,downloadQuestionAllReport,
	  hasReport, getPenalizedTeam, getCtfAddressDetails, getTeamSolveStatic} from '@/api/compitionStatic'
  import {ctfReport,queryCtfTarget,getRefereeAllotTargetList} from '@/api/drill_compete'
  import {getaccessgroupmember} from '@/api/access_new'
  import tableBody from './tableListComponent'
  import groupMixin from "@/mixin/groupMixin";
  import PackageProgress from '@/components/package-progress/package-progress.vue'
  import encryption from '@/libs/encryption.js'
	export default {
    name: 'scenes',
    props:['sceneId','sceneName','poll', 'isBasicScore','disabledAllBtn','isDistributed','isMainRange','wpUpMode','hasReportTarget'],
	mixins: [groupMixin],
	data(){
		let September = sessionStorage.getItem('November');
    	September = JSON.parse(encryption.SelfUseDecrypt(September));
		const d = function(val){
		this.getRankingStatic(null,null,val)
		}.bind(this);
		const exportFile = function(val){
		this.exportFile();
		}.bind(this);
		const exportScoreRecord = function(val){
		this.exportScoreRecord();
		}.bind(this);
		const downloadAllReport = function(val){
		this.downloadAllReport();
		}.bind(this);
	  	return {
			USER_ID: September.userId,
			questionModal:{
				show:false,
				question:''
			},
			currentTeam: {},
            showModal: false,
            title: '',
            staticColumns: [],
            teamId: '',
            finishStatus: '',
            staticCurrentPage: 1,
            staticPageSize: 10,
            staticTotal: 0,
            staticList: [],
            pageNow: 1,
			pageSize:10,
			showProgress: false, // 展示进度
			progress: 0, // 进度
			progressStatus: 'active',
	  	    selFiles:[],
	  	    initObj:{
             Button:[
                {
                    name:'导出排行',
                    fnName:exportFile
                },
                {
                    name:'导出得分记录',
                    fnName:exportScoreRecord
                },
                {
                    name:'打包下载所有报告',
                    fnName:downloadAllReport,
                    disabled: true
                }
            ],
            Input:[
            ],
            Select:[
				{
					optionsValue: [],
					placeholder: `请选择团队`,
					fnName: this.getRankingStaticById
				}
            ],
            DatePicker:{
              isShow:false,
              fnName:d,
            },
            Page:{
              total:0,
              currentPage:1,
              pageSize:10
            },
			currentTeam: {},
            Table:{
              listCol:[
//            	{
//            		placement:'top-left',
//            		render:(h,params) => {
//            			return h('Checkbox',{
//            				props:{
//            					disabled:!params.row.report
//            				},
//            				on:{
//            					'on-change':(e) => {
//            						if(e){
//            							this.selFiles.push(params.row.fileId);
//            						}else{
//            							let index = this.selFiles.finIndex(file => file.fileId == params.row.fileId);
//            							this.selFiles.splice(index,1);
//            						}
//            					}
//            				}
//            			})
//            		}
//            	},
                {
               	  title: '排行',
                  align: 'center',
                  key:'rank',
//                width:60,
                  placement:'top-right',
                  order:1,
                  render:(h,params) => {
		            	let ele;
		            	if(params.row._index < 3 && this.curPage == 1){
		            		ele = h('img',{
		            			attrs:{
		            				src:require(`../../../../assets/scene/top${params.row._index+1}.png`)
		            			},
		            			style:{
		            				display:'inline-block',
//		            				width:'20px',
		            				verticalAlign: 'text-bottom',
    								marginLeft: '20px'
		            			}
		            		})
		            	}else{
		            		ele = h('span',params.row._index+1 + (this.curPage-1)*10)
		            	}
		            	let index = params.row._index+1;
		            	let color = 'var(--default-color)';
		            	if(this.curPage == 1){
			            	if(index == 1){
			            		color = '#f34938';
			            	}else if(index == 2){
			            		color = '#eb8205';
			            	}else if(index == 3){
			            		color = '#27b666';
			            	}else{
			            		color = 'var(--default-color)';
			            	}
			            }
		            	return h('span',[
		            		h('span',{
		            			style:{
		            				color:color
		            			}
		            		},'排行'),
		            		ele
		            	]);
		            }
                },
                {
                  title:'团队名称',
                  key:'teamName',
                  align:'center',
                  ellipsis:true,
                  tooltip:true,
                  placement:'top-left',
                  order:1,
					width: 240
                },
//              {
//                title:'势力方名称',
//                key:'partyName',
//                align:'center',
//                ellipsis:true,
//                tooltip:true,
//              },
                {
                  title:'得分',
                  key:'totalScore',
                  align:'center',
                  ellipsis:true,
                  tooltip:true,
                  width:60,
                },
                {
                  title:'解决题目数',
                  key:'finishTotal',
                  align:'center',
                  width:60,
                  render:(h,params) => {
        			return h('Tag',{
        				props:{
        					color:'blue'
        				},
        				style:{
        					cursor:'pointer !important'
        				},
        				attrs:{
        					title:'点击查看解决题目详情'
        				},
        				nativeOn:{
        					'click':() => {
        						this.getAttackSuccess(params.row);
        						this.submitRecordModal = true;
        					}
        				}
        			},params.row.finishTotal)
                  }
                },
                {
					title: '未解决题目数',
					key:'notFinishTotal',
					width: 120,
					render:(h,params)=>{
						return h('Tag',{
							props:{
								color:'blue'
							},
                            style:{
                                cursor:'pointer !important'
                            },
                            attrs:{
                                title:'点击查看未解决题目详情'
                            },
							nativeOn:{
								click:()=>{
									this.showModalFn(params.row.teamId, 0, params.row.teamName)
								}
							}
						}, params.row.notFinishTotal)
					}
				},
                {
                    title:'撤销数',
                    key:'cheatTotal',
                    align:'center',
                    width:60,
                    render:(h,params)=>{
                        return h('Tag',{
                            props:{
								color:'blue'
							},
                            style:{
                                cursor:'pointer !important'
                            },
                            attrs:{
                                title:'点击查看撤销题目详情'
                            },
                            nativeOn:{
                                click:()=>{
                                    this.showModalFn(params.row.teamId, 2, params.row.teamName)
                                }
                            }
                        }, params.row.cheatTotal)
                    }
                },
                {
                	title:'团队成员',
                	key:"groupUsrs",
                	render:(h,params) => {
                		let tagArr = [];
                		tagArr = params.row.teamMembers && params.row.teamMembers.map(user => {
                			return h('Tag',{
                				props:{
                					color:'purple'
                				}
                			},user);
                		})
                		return h('div', {
							style: {
								display: 'flex',
                                    'flex-wrap': 'wrap'
                                },
						}, tagArr.length > 0 ? tagArr : '无')
                	}
                },
				{
                  title:'是否提交报告',
                  key:'report',
                  align:'center',
                  ellipsis:true,
                  tooltip:true,
                  placement:'top-right',
                  render:(h,params) => {
                  	return h('Tag',{
                  		props:{
                  			color:params.row.report == 0 ? 'var(--status-no)': 'var(--status-yes)'
                  		}
                  	},params.row.report == 0 ? '否': '是')
                  }
                },
				{
					title: '操作',
					key: 'action',
					width: 120,
					opList: [
						{
							txt: '下载',
							disabled: (data) => {
								return !data.report || this.disabledAllBtn;
							},
							fun: this.downloadTeamAllReport
						},
						{
							txt: '预览',
							disabled: (data) => {
								return !data.report || this.disabledAllBtn;
							},
							fun: (data) => {
								//新的预览接口
								window.open(`/api/minio/filePreview?id=${data.fileIds[0]}`);
							}
						}
					]
				},
                {
                	title:'操作',
                	key:'action1',
                	placement:'top-right',
					show:false,
                	render:(h,params) => {
                		return h('div',[
                			h('Button',{
							  props:{
							    type:'primary',
							    size:'small',
							    disabled:!params.row.report||this.disabledAllBtn
							  },
							  style:{
							    marginRight:'5px'
							  },
							  on:{
							    click:()=>{
							    	this.downloadTeamAllReport(params.row)
							    }
							  }
							},'下载'),
							h('Button',{
							  props:{
							    type:'primary',
							    size:'small',
							    disabled:!params.row.report||this.disabledAllBtn
							  },
							  style:{
							    marginRight:'5px'
							  },
							  on:{
							    click:()=>{
							    	//新的预览接口
							    	window.open(`/api/minio/filePreview?id=${params.row.fileIds[0]}`);
							    	return;
							    	let reviewUrl = `/api/ftp/edu-ftp/viewOnline/pdf/${params.row.fileId}`;
							    	this.pdfUrl = `static/pdfjs/web/viewer.html?file=${encodeURIComponent(reviewUrl)}`
							    	this.pdfModal = true;
							    }
							  }
							},"预览"),
                		])
                	}
                },
//              {
//                title:'攻击成功次数',
//                key:'attackCount',
//                align:'center',
//                ellipsis:true,
//                tooltip:true,
//                render:(h,params)=>{
//                  return h('span', params.row.attackCount||0)
//                }
//              },
//              {
//                title:'防守失败次数',
//                key:'defenseFailedCount',
//                align:'center',
//                ellipsis:true,
//                render:(h,params)=>{
//                  return h('span', params.row.defenseFailedCount||0)
//                }
//              }
              ],
              listData:[]
            },
            Fnlist:'getRankingStatic',
        },
//      sencenId:'',
        selName:'',
        timeout:{},
        curPage:1,
        pdfUrl:'',
		pdfModal:false,
		submitRecordModal:false,
		listCol:[
            {
				type: 'index',
				align: 'center',
				ellipsis:true,
				width:60
            },
//          {
//   	         title:'团队名称',
//        	    key:'teamName',
//          	  align:'center',
//           	 ellipsis:true,
//            	tooltip:true,
//           	 placement:'top-left',
//           	 order:1
//          },
            {
				title:'已解决题目名称',
				key:'targetName',
				align:'center',
				ellipsis:true,
				tooltip:true,
//           	width:100
            },
            {
				title:'提交者',
				key:'userName',
				align:'center',
				ellipsis:true,
				tooltip:true,
//              width:100
            },
            {
				title:'提交内容',
				key:'content',
				align:'center',
				ellipsis:true,
				tooltip:true,
//            width:100
            },
            {
				title:'提交时间',
				key:'createTime',
				align:'center',
				ellipsis:true,
				tooltip:true
            },
            {
				title:'得分',
				key:'score',
				align:'center',
				ellipsis:true,
				placement:'top-right',
//            width:60,
              	render:(h,params) => {
				  	if (!this.isBasicScore) {
						return h('Tag',{
							props:{
								color:params.row.score > 0 ? 'success' :'default',
								type:"border"
							},
							on:{
								click:()=>{
								}
							}
						}, params.row.isRight == 1 ? params.row.score : 0 )
				  	} else {
						return h('Button', {
							props: {
								type: 'info',
							},
							on:{
								click: (e) => {
									this.getPenalizedTeam(params.row.teamId, params.row.targetId, params.row.teamName, params.row.targetName)
								},
							}
						}, params.row.isRight == 1 ? params.row.score : 0);
					}
              	}
            }
        ],
		columns: [
			{
				title: '团队名',
				key: 'teamName',
			},
			{
				title: '被扣分数',
				key: 'score',
			}
		],
		tableLoading: false,
		penalizedTeamList: [],
        rightSubmitList:[],
        rightSubmitTotal:0,
		penalizedModal: false,
		penalizedTitle: '',
		targetList:[]
      }
	},
    components:{
//    'title-top':titleTop,
      'table-body':tableBody,
		PackageProgress
    },
    watch:{
		teamList(newValue) {
			this.initObj.Select[0].optionsValue = newValue
		},
		submitRecordModal(val) { // 关闭模态框后，重置到首页数据
			if (!val) {
				this.pageNow = 1
			}
		}
    },
    created(){
      //this.getRankingStatic();
    },
    beforeDestroy(){
		clearTimeout(this.timeout)
	},
	mounted(){
    	this.getRankingStatic();
    	this.hasReport()
		if(this.isDistributed==1&&this.isMainRange!=1){
			this.initObj.Button.splice(2,1)
		}
		if(this.wpUpMode === 2 && this.hasReportTarget) { //针对题目提交
			this.initObj.Button.push({
				name:'按照题目下载报告',
				fnName:this.openQuestionModal,
				disabled: true
			})
		}
		if (this.isBasicScore) {
			this.initObj.Table.listCol.splice(2, 1, {
				title:'基础分',
				key:'basicScore',
				align:'center',
				ellipsis:true,
				tooltip:true,
				width:60,
			}, {
				title:'得分',
				key:'totalScore',
				align:'center',
				ellipsis:true,
				tooltip:true,
				width:60,
			},{
				title:'扣分',
				key:'subScore',
				align:'center',
				ellipsis:true,
				tooltip:true,
				width:60,
			},{
				title:'总分',
				key:'lastScore',
				align:'center',
				ellipsis:true,
				tooltip:true,
				width:60,
			})
		}
	},
  	methods:{
		openQuestionModal(){
			this.questionModal.show = true;
			this.questionModal.question = '';
			this.getCtfTargetTeamList()
		},
		getCtfTargetTeamList(){
			if(this.sceneId){
				let params = {
					pageIndex:1,
					pageSize:1000,
					userId:this.USER_ID
				}
				getRefereeAllotTargetList(this.sceneId,params).then(({code,data,message}) => {
					if(code == 1){
						this.targetList  = data.items.map(item => {
							return {
								...item,
								questionId:item.targetId,
								name:item.targetName
							}
						});
					}else{
						this.targetList = [];
						this.total = 0;
					}
				}).catch(error => {
					this.list = [];
					this.total = 0;
				})
			}else{
				let params = {
					pageIndex:1,
					pageSize:1000,
					isNeedSubmitFlag: 0,
					submitFlag: 0,
					needEnv: 0,
					isNeedEnv: 0
				}
				queryCtfTarget(this.$route.query.id,params).then(data => {
					if(data.code==1){
						this.targetList = data.data.items;
					}else{
						this.$Message.error('获取列表失败');
					}
				}).catch(error => {
					this.$Message.error('获取列表失败');
				})
			}
        },
        staticChangePage(val) {
            this.staticCurrentPage = val
            this.getTeamSolveStatic()
        },
        staticChangePageSize(val) {
            this.staticPageSize = val
            this.getTeamSolveStatic()
        },
		pageChange(page) {
			this.pageNow = page
			this.getAttackSuccess()
		},
	  	getPenalizedTeam(teamId, targetId, teamName, targetName) {
			this.penalizedModal = true
			this.penalizedTitle = `${teamName} / ${targetName}`
	        this.tableLoading = true
            getPenalizedTeam({
                sceneId: this.sceneId  || this.$route.query.id,
                teamId,
                targetId
            }).then(({ code, data, message }) => {
                if (code !== 1) {
                    this.$Message.warning(message)
                } else {
                    this.penalizedTeamList = data.items
					console.log(this.penalizedTeamList)
                }
            }).finally(() => {
                this.tableLoading = false
            })
        },
	  // 查询比赛是否有解题报告，没有的情况下不允许打包下载
	  hasReport() {
		  let sceneId = this.sceneId  || this.$route.query.id
		  hasReport(sceneId).then(({code, data, message}) => {
		  	if (code !== 1) {
		  		this.$Message.warning(message)
			} else {
		  		this.initObj.Button.forEach(item => {
		  			if (item.name === '打包下载所有报告' || item.name === '按照题目下载报告') {
						this.$set(item, 'disabled', !data)
					}
				})
			}
		  }).catch(error => {
		  	this.$Message.error('查询是否存在解题报告异常')
		  })
	  },
	  change(val) {
	  	this.showProgress = val
	  },
	  getRankingStaticById(id) {
		  this.selName = this.getTeamNameById(id);
		  this.getRankingStatic();
	  },
    async getRankingStatic(page,pageSize,querytime){
      let _this = this;
      let pages = page || 1;
	  this.$set(this.initObj.Page, 'currentPage', pages)
      let rows = pageSize||_this.PZ|| 10;
      let id = '';
      let params={
        pageIndex : pages,
        pageSize : rows
      };
      this.curPage = pages;
      if(this.selName){
        params.teamName =  this.selName;
      }
      //if(querytime){
        //params.createtime = querytime[0];
        //params.lastupdatetime = querytime[1];
        //console.log(querytime)
      //}
	  let sceneId = this.sceneId || this.$route.query.id;
      if(sceneId){
        ctfTeamRankStatis(sceneId,params).then(data=>{
          if(data.code==1){
            let listData = data.data.items;
//          if(_this.initObj.Table.listData.length > 0 && !type){
//          	listData.forEach(item => {
//	            	let data = _this.initObj.Table.listData.filter(rank => rank.id == item.id)[0];
//	            	if(!data.groupUsers){
//	            		this.getaccessgroupmember(item);
//	            	}else{
//	            		item.groupUsers = data.groupUsers;
//	            	}
//	            	_this.initObj.Table.listData = listData;
//	            	if(data.report == 1){
//          			this.ctfReport(item);
//          		}
//	            })
//          }else{
//          	let listData = data.data.items;
            	let proArr = listData.map(async item => {
            		this.$set(item,'fileIds','');
		   	  			this.$set(item,'fileNames','');
		   	  			this.$set(item,'groupUsers',[]);
            		if(item.report == 1){
            			await this.ctfReport(item);
            		}
            		await this.getaccessgroupmember(item);
            	})
            	Promise.all(proArr).then(data => {
            		_this.initObj.Table.listData = listData;
            	})
//          }
		//接口直接返回成员无需查询
			_this.initObj.Table.listData = listData;
            _this.initObj.Page.total = data.data.total;
			console.log(_this.initObj.Table.listData,'_this.initObj.Table.listData_this.initObj.Table.listData');
            clearTimeout(this.timeout)
            if(this.poll){ //如果需要轮询
            	this.timeout = setTimeout(() => {
            		this.getRankingStatic(page,pageSize);
            	},10000)
            }
          }
        })
      }
    },
    saveInfo(val){
      console.log('this is test');
      console.log(val);
    },
    exportFile(){
	  	let sceneId = this.sceneId || this.$route.query.id;
	  	let sceneName = this.sceneName || this.$route.query.name;
	  	let a = document.createElement("a");
	    document.body.appendChild(a);
	    a.href = `/api/compete/ctfGameBox/export/${sceneId}/${sceneName}`;
	    a.download = ''; //命名下载名称
	    a.click(); //点击触发下载
	    a.remove();
	},
	exportScoreRecord(){
		let sceneId = this.sceneId  || this.$route.query.id;
	  	let sceneName = this.sceneName || this.$route.query.name;
	  	let a = document.createElement("a");
	    document.body.appendChild(a);
	    a.href = `/api/compete/ctfGameBox/exportSubmit/${sceneId}/${sceneName}`;
	    a.download = ''; //命名下载名称
	    a.click(); //点击触发下载
	    a.remove();
	},
	ctfReport(item){
		return new Promise(resolve => {
	   	    let sceneId = this.sceneId || this.$route.query.id;
	   	    let teamId = item.teamId;
	   	    ctfReport(sceneId,teamId).then(data => {
		   	  	if(data.code == 1 && data.data){
		   	  		this.$set(item,'reportIds',data.data.map(file =>file.id));
		   	  		this.$set(item,'fileIds',data.data.map(file =>file.fileId));
		   	  		this.$set(item,'fileNames',data.data.map(file =>file.fileName));
		   	  		resolve(true);
		   	  	}else{
		   	  		resolve(false);
		   	  	}
	   	    }).catch(error => {
	   	    	resolve(false);
	   	    })
	    })
    },
    //获取团队成员
    getaccessgroupmember(group){
    	return new Promise(resolve => {
    		getaccessgroupmember(group.teamId).then(data => {
	    		if(data.code == 1){
	    			group.groupUsers = data.data;
	    			resolve(true);
	    		}else{
	    			this.$Message.error('获取团队成员失败！');
	    			resolve(false);
	    		}
	    	}).catch(error => {
	    		this.$Message.error('获取团队成员失败！');
	    		resolve(false);
	    	})
    	})
    },
    downloadAllReport(){
    	let sceneId = this.sceneId  || this.$route.query.id;
    	this.showProgress = true
    	downloadSceneAllReport(sceneId,[],this.downFileProgress).then(data => {
			this.total = 0
    		if(data.type == 'application/octet-stream'){
                const downloadElement = document.createElement("a");
                const href = window.URL.createObjectURL(data);
                downloadElement.href = href;
                downloadElement.download = '解题报告.zip';
                document.body.appendChild(downloadElement);
                downloadElement.click();
                document.body.removeChild(downloadElement); // 下载完成移除元素
                window.URL.revokeObjectURL(href); // 释放掉blob对象
    		}else{
    			this.$Message.error('下载报告失败!不存在文件数据！');
    		}
    	}).catch(error => {
    		this.progressStatus = 'wrong'
    		this.$Message.error('下载报告失败!');
    	}).finally(() => {
			this.progress = 100
    		setTimeout(() => {
				this.showProgress = false
				this.progressStatus = 'active'
				this.progress = 0
			}, 2000)
		})
    },
	downloadQuestionAllReport(){
		let sceneId = this.sceneId  || this.$route.query.id;
    	this.showProgress = true
		let {questionId,name} = this.targetList.find(item => item.questionId === this.questionModal.question)
    	downloadQuestionAllReport(sceneId,questionId,{questionName:name},this.downFileProgress).then(data => {
			this.total = 0
    		if(data.type == 'application/octet-stream'){
                const downloadElement = document.createElement("a");
                const href = window.URL.createObjectURL(data);
                downloadElement.href = href;
                downloadElement.download = `${name}_解题报告.zip`;
                document.body.appendChild(downloadElement);
                downloadElement.click();
                document.body.removeChild(downloadElement); // 下载完成移除元素
                window.URL.revokeObjectURL(href); // 释放掉blob对象
    		}else{
    			this.$Message.error('下载报告失败!不存在文件数据！');
    		}
    	}).catch(error => {
    		this.progressStatus = 'wrong'
    		this.$Message.error('下载报告失败!');
    	}).finally(() => {
			this.progress = 100
    		setTimeout(() => {
				this.showProgress = false
				this.progressStatus = 'active'
				this.progress = 0
			}, 2000)
		})
	},
	  downFileProgress(progress){
		  let currentProgress = progress.loaded * 1; //B单位
		  if (this.total) {
			  this.total += currentProgress
		  } else {
			  this.total = currentProgress
		  }
		  currentProgress = this.total - currentProgress ? currentProgress : currentProgress / 2;
		  let rate = (((this.total-currentProgress)/this.total)*100).toFixed(2)*1;
		  if(!this.rate || rate > this.rate){
			  this.progress = rate;
		  }
	  },
    downloadTeamAllReport(data){
	    	let sceneId = this.sceneId || this.$route.query.id;
	    	let teamName = data.teamName;
	    	downloadSubmitAllReport(sceneId,data.teamName,data.reportIds).then(data => {
	    		if(data.type == 'application/octet-stream'){
	                const downloadElement = document.createElement("a");
	                const href = window.URL.createObjectURL(data);
	                downloadElement.href = href;
	                downloadElement.download = `${teamName}_解题报告.zip`;
	                document.body.appendChild(downloadElement);
	                downloadElement.click();
	                document.body.removeChild(downloadElement); // 下载完成移除元素
	                window.URL.revokeObjectURL(href); // 释放掉blob对象
	    		}else{
	    			this.$Message.error('下载报告失败!不存在文件数据！');
	    		}
	    	}).catch(error => {
	    		this.$Message.error('下载报告失败!');
	    	})
	    },
        getAttackSuccess(team){
            this.currentTeam = team || this.currentTeam
            let params={
                pageIndex : this.pageNow,
                pageSize : this.pageSize,
                sceneId:this.sceneId || this.$route.query.id,
                isRight:1,
                teamId:this.currentTeam.teamId,
                status: 1
            };
            getCtfAddressDetails(params).then(data=>{
                if(data.code==1){
                this.rightSubmitList = data.data.items;
                this.rightSubmitTotal = data.data.total;
                }else{
                    this.$Message.error(data.message);
                }
            }).catch(error => {
                this.$Message.error(data.message);
            })
        },
        // 显示模态框，重置所有数据
        showModalFn(teamId, finishStatus, title) {
            this.showModal = true
            this.title = `${title}_${finishStatus === 2 ? '撤销题目详情' : '未解决题目详情'}`
            if (finishStatus === 1) { // 提交成功
                this.staticColumns = [
                    {
                        title: '已完成题目名称',
                        key: 'questionName'
                    },
                    {
                        title: '攻破时间',
                        key: 'finishTime'
                    },
                    {
                        title: '分数',
                        key: 'ctfScore'
                    },
                    {
                        title: '得分',
                        key: 'score'
                    }
                ]
            } else if (finishStatus === 2) { // 撤销
                this.staticColumns = [
                    {
                        title: '已撤销题目名称',
                        key: 'questionName'
                    },
                    {
                        title: '攻破时间',
                        key: 'finishTime'
                    },
                    {
                        title: '题目分数',
                        key: 'ctfScore'
                    },
                    {
                        title: '撤销得分',
                        key: 'score'
                    }
                ]
            } else {
                this.staticColumns = [
                    {
                        title: '未解决题目名称',
                        key: 'questionName'
                    },
                    {
                        title: '分数',
                        key: 'ctfScore'
                    }
                ]
            }
            this.teamId = teamId
            this.finishStatus = finishStatus
            this.staticCurrentPage = 1
            this.staticPageSize = 10
            this.getTeamSolveStatic()
        },
        // 查询题目完成详情
        getTeamSolveStatic(currentPage) {
            if (currentPage !== undefined) {
                this.staticCurrentPage = currentPage
            }
            getTeamSolveStatic({
                pageIndex: this.staticCurrentPage,
                pageSize: this.staticPageSize,
                sceneId: this.sceneId  || this.$route.query.id,
                teamId: this.teamId,
                finishStatus: this.finishStatus
            }).then(({ code, data, message }) => {
                if (code === 1) {
                    let { total, items } = data || {}
                    this.staticTotal = total || 0
                    this.staticList = items || []
                } else {
                    this.$Message.warning(message)
                }
            }).catch(() => {
                this.$Message.error('获取团队题目完成详情异常');
            })
        }
    },
}
</script>

<style>
  .drillsTable .ivu-poptip-body {
    text-align: left!important;
  }
  .scenesHeader{
    margin-bottom: 16px;
  }
  .drillTables{
    min-height: 300px;
  }
  .drillsTable.ivu-table-wrapper{
    overflow: inherit;
  }
</style>
<style scoped>
  .Titles{
    background: #eeeeee;
    margin: 16px auto;
    padding: 10px 0;
  }
  .targetHeader{
    padding: 10px;
    margin-bottom: 10px;
  }
</style>
